﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Hetang.Models.Validator
{
    /// <summary>
    /// 必填
    /// </summary>
    public class MyRequiredAttributeAdapter : System.Web.Mvc.RequiredAttributeAdapter
    {
        public MyRequiredAttributeAdapter(ModelMetadata metadata, ControllerContext context, RequiredAttribute attribute) : base(metadata, context, attribute) { }

        public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
        {
            string errorMessage = string.Format("{0} 是必须填写的！", Metadata.DisplayName);
            return new[] { new ModelClientValidationRequiredRule(errorMessage) };
        }
    }
}